package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.example.myapplication.dummy.DummyContent;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;

public class addActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.addactivity_main3);
        Button button = findViewById(R.id.commit);
        EditText editText = findViewById(R.id.editText3);
        EditText editText2 = findViewById(R.id.editText4);
        EditText editText3 = findViewById(R.id.editText5);
        EditText editText4 = findViewById(R.id.editText6);
        EditText editText5 = findViewById(R.id.editText7);
        EditText editText6 = findViewById(R.id.editText8);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String str  = editText.getText().toString();
                String str2  = editText2.getText().toString();
                String str3  = editText3.getText().toString();
                String str4  = editText4.getText().toString();
                String str5 = editText5.getText().toString();
                String str6  = editText6.getText().toString();
                Map<String,String >  map=new HashMap<>();
                map.put("itemName",str);
                map.put("itemDesc",str2);
                map.put("itemRemark",str3);
                map.put("initPrice",str4);
                map.put("kindId",str5);
                map.put("avail",str6);
                System.out.println(map);
                try {
                    String re = OkHttpUtil.postRequest("http://172.18.85.254:8080/auction/api/items",map);
                    System.out.println(re);
                    Intent intent = new Intent(addActivity.this,IndexActivity.class);
                    startActivity(intent);
                } catch (ExecutionException e) {
                    e.printStackTrace();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
    }
}
